#import <UIKit/UIKit.h>

#define SINGLE_LINE_WIDTH				(1 / [UIScreen mainScreen].scale)
#define SINGLE_LINE_ADJUST_OFFSET		((1 / [UIScreen mainScreen].scale) / 2)

typedef NS_ENUM(NSInteger, MRChartStyle) {
    MRChartStyleLine      = 0,
    MRChartStyleSquare    ,
};

typedef NS_ENUM(NSInteger, MRTextAlignment) {
	MRTextAlignmentLeft		= NSTextAlignmentLeft,
	MRTextAlignmentCenter	= NSTextAlignmentCenter,
	MRTextAlignmentRight	= NSTextAlignmentRight,
	
	MRTextAlignmentTop		= 1,
	MRTextAlignmentVCenter	= 0,
	MRTextAlignmentBottom	= 2,
};



/*===================================================================
 说明:
    图表参考线
 ==================================================================*/
@class MRChart;
@interface MRChartLine : NSObject

@property (nonatomic, readonly) MRChart     *chart;

@property (nonatomic) CGFloat       value;			//参考值，相对于Chart的[minValue, maxValue]
@property (nonatomic) CGFloat       lineWidth;		//线宽(默认2.0)

@property (nonatomic, retain) NSArray <NSNumber *>  *lineDash;		//线样式
@property (nonatomic, retain) UIColor   *lineColor;		//线颜色(默认为chart颜色)

@property (nonatomic, copy)   NSString  *text;			//参考线文本
@property (nonatomic, retain) UIFont    *textFont;		//参考线文本字体
@property (nonatomic, retain) UIColor   *textColor;		//参考线文本颜色(默认为线颜色)
@property (nonatomic)		  CGPoint   textAlign;		//文本对齐(水平与垂直，参考Chart的textAlign)

@end

/*===================================================================
 说明:
    图表属性
 ==================================================================*/
@class MRChartView;
@interface MRChart : NSObject

- (instancetype)initWithChartView:(MRChartView *)chartView;

@property (nonatomic, readonly) MRChartView     *chartView;

@property (nonatomic, assign) MRChartStyle	style;
@property (nonatomic, assign) NSInteger		tag;
@property (nonatomic, copy)	  NSString		*name;			//图表数据名称(在footer中为固定脚注内容)

@property (nonatomic, assign) BOOL          continuous;         //MRChartStyleLine样式中是否连续绘制（默认YES），NO时将不绘制低于最低值的线段
@property (nonatomic, retain) NSArray		*lineDash;			//线样式
@property (nonatomic, assign) CGFloat		lineWidth;			//线宽(默认2.0)

@property (nonatomic, assign) CGFloat		maxValue;			//最大值(默认1)
@property (nonatomic, assign) CGFloat		minValue;			//最小值(默认0)
@property (nonatomic, assign) CGFloat		pointSize;			//数据点大小(默认0，不显示), MRChartStyleSquare时控制图形左边距

//颜色属性(若为数组，则按数组颜色渐变绘制)
@property (nonatomic, retain) id        lineColor;      //数据线颜色(柱状样式为顶边颜色)，为nil则不绘制数据线
@property (nonatomic, retain) id        fillColor;      //数据区填充颜色，若为nil则不填充区域(若为数组，则绘制渐变色)

@property (nonatomic, retain) UIColor   *maxLineColor;  //柱状样式最大值顶边颜色(仅用于 MRChartStyleSquare)
@property (nonatomic, retain) UIColor   *minLineColor;  //柱状样式最小值顶边颜色(仅用于 MRChartStyleSquare)
@property (nonatomic, retain) id        maxFillColor;   //柱状样式最大值填充颜色(仅用于 MRChartStyleSquare)
@property (nonatomic, retain) id        minFillColor;   //柱状样式最小值填充颜色(仅用于 MRChartStyleSquare)

//轴文本
@property (nonatomic, retain) UIFont    *textFont;      //文本字体
@property (nonatomic, retain) UIColor   *textColor;     //刻度颜色，若为nil则不绘制刻度
@property (nonatomic) CGPoint			textAlign;		//文本位置 >0 AND <1 为居中百分比值(在footer中此值用于控制固定脚注位置)

@property (nonatomic, readonly) NSMutableArray <MRChartLine *>	*lines;		//参考线
- (MRChartLine *)addLineWithText:(NSString *)text value:(CGFloat)value;

//数据点
@property (nonatomic, retain) NSMutableArray <NSDictionary *>	*points;	//数据点（可以直接赋值）

- (void)addPointWithDictionary:(NSDictionary <NSNumber *, id> *)dictionary;
- (void)addPointWithArray:(NSArray <NSDictionary <NSNumber *, id> *> *)points;

@end

/*===================================================================
 说明:
    图表视图
 ==================================================================*/
@interface MRChartView : UIScrollView <UIScrollViewDelegate>

@property (nonatomic) BOOL			allowZoom;      //允许缩放
@property (nonatomic, readonly) UIPinchGestureRecognizer	*gestureRecognizer;

@property (nonatomic) CGFloat		pointCount;		//点数
- (void)setPointCount:(CGFloat)pointCount animated:(BOOL)animated;		//设置总点数

@property (nonatomic) CGFloat		pointWidth, minPointWidth, maxPointWidth;	//点宽

@property (nonatomic) CGSize		gridSize;       //网格大小(默认1*8)
@property (nonatomic) NSArray       *gridDash;      //网格线样式(默认@[2, 2]虚线)
@property (nonatomic) CGFloat		gridWidth;		//网格线宽(默认1像素)
@property (nonatomic, copy)	id      gridColor;		//网格颜色
@property (nonatomic, copy) id      gridBkColor;    //网格背景颜色

@property (nonatomic) UIEdgeInsets  border;			//边框四边宽度（默认每边1像素）
@property (nonatomic, copy)	id      borderColor;    //边框颜色

@property (nonatomic, readonly) MRChart *footer;	//脚注（脚注引用MRChart对象，除不能绘制外，大部分属性有用）
@property (nonatomic) CGFloat		footerHeight;	//脚注高度
@property (nonatomic) CGPoint		footerAlign;	//脚注名称对齐(脚注数据由 footer.textAligh 控制)
@property (nonatomic) UIColor		*footerColor;	//脚注名称颜色(脚注数据由 footer.textColor 控制)

@property (nonatomic, readonly) NSMutableArray <MRChart *>	*charts;

//添加的图表按先添加先绘制顺序，因此最后添加的将画在最上层
- (MRChart *)addChartWithName:(NSString *)name;
- (MRChart *)chartWithName:(NSString *)name;

- (void)removeChart:(MRChart *)chart;				//
- (void)removeChartWithName:(NSString *)name;		//

- (void)addPointWithDictionary:(NSDictionary *)dictionary;
- (void)addPointWithArray:(NSArray *)points;

@end
